#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
#include "PathNode.h"
#include "SymbolNode.h"
#include "MovieClipNode.h"
#include "translator.h"
#include <QFile>
#include <QTextStream>
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
	PathNode rec,rec1;
    rec1.LinePenRef().setWidth(1);
    rec1.FillBrushRef().setColor(QColor(100,100,0,100));
    rec1.AddSharpPoint(QPointF(0,0),QPointF(-50,-50));
    rec1.AddSharpPoint(QPointF(00,200),QPointF(-50,150));
    rec1.AddSharpPoint(QPointF(100,400),QPointF(50,350));
    rec1.MoveLControlPointAt(0,-50,200);
    //rec1.SetScale(1.2,1.5);
    rec1.ClosePath();
    rec.LinePenRef().setWidth(1);
    rec.FillBrushRef().setColor(QColor(100,0,0,200));
    rec.AddLinearPoint(QPointF(0,0));
    rec.AddLinearPoint(QPointF(0,200));
    rec.AddLinearPoint(QPointF(100,400));
    rec.ClosePath();
    //rec.SetPos(100,100);
    //rec.ChangePointType(2,smooth);
    //rec.MoveRControlPointAt(2,400,400);
    rec.SetAxis(0,0);
    rec.SetAngle(30);
    //rec.UpdateCache();

    SymbolNode group; group.SetPos(100,100,0);
    group.AddChildren(new PathNode(rec));
    group.AddChildren(new PathNode(rec1));
    group.SetAxis(100,100,0);
    group.SetAngle(-70);
	//group.SetAngle(0,30);
    //MovieClipNode movie1;
    movie1.AddChildren(new SymbolNode(group));
    group.SetAngle(-90);
	group.SetSkew(0,40);
	group.SetAlpha(0.5);
    //group.SetScale(0.3,0.3,0);
    movie1.AddChildren(new SymbolNode(group));
    //group.SetScale(0.4,0.5,0);
    movie1.SetAngle(-40);
	//movie1.SetAlpha(0.4,0);
    movie1.UpdateCache();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::paintEvent(QPaintEvent *event)
{
	
    QPainter painter(this);
    
    painter.save();
    painter.translate(movie1.GetPos(0).x(),movie1.GetPos(0).y());
    painter.drawImage(movie1.CacheOffsetX(),movie1.CacheOffsetY(),movie1.GetImage());
    Translator trans;
    trans.Initialize("test1",24);
    trans.parseRootNode(&movie1);

    QFile file( "file.txt" );
    if ( file.open(QIODevice::WriteOnly ) )
    {
        QTextStream stream( &file );
        stream <<trans.Result();
        file.close();
    }

    //trans.Result();
}

